package com.example.map.mvpdemo.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.map.mvpdemo.R;
import com.example.map.mvpdemo.presenter.UserPresenter;

/**
 *
 */
public class MainActivity extends AppCompatActivity implements IUserView {
    private EditText ed_userName,ed_Pwd;
    private Button btn_login;private ProgressBar pb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    /**
     * 初始化控件
     */
    private void initViews() {
        ed_userName= (EditText) findViewById(R.id.ed_username);
        ed_Pwd= (EditText) findViewById(R.id.ed_pwd);
        pb= (ProgressBar) findViewById(R.id.pg);
        btn_login= (Button) findViewById(R.id.btn_login);
        final UserPresenter u=new UserPresenter(this);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              u.Login();
            }
        });


    }

    @Override
    public void showpb() {
     pb.setVisibility(View.VISIBLE);
    }
    @Override
    public void hidepb() {
      pb.setVisibility(View.GONE);
    }

    @Override
    public String getUsername() {
        return ed_userName.getText().toString().trim();
    }

    @Override
    public String getPwd() {
        return ed_Pwd.getText().toString().trim();
    }

    @Override
    public void doBussiness() {
        Toast.makeText(this,"登录成功以后逻辑!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void Fail() {
        Toast.makeText(this,"登录失败以后逻辑!", Toast.LENGTH_SHORT).show();
    }
}
